package com.lq.createPattern.singleton.type1;

public class SingletonTest1 {
    public static void main(String[] args) {
        Singleton singleton =Singleton.getInstance();
        Singleton singleton1 = Singleton.getInstance();
        System.out.println(singleton1==singleton);
        System.out.println(singleton1.hashCode());
        System.out.println(singleton.hashCode());
    }
}
//饿汉式 静态变量
class Singleton{
    //1.构造器私有化，防止外部能new
    private Singleton() {
    }
    //2.本类内部类创建对象实例
    private final  static Singleton instance =new Singleton();
    //3.提供一个公有的静态方法，返回对象实例
    public static Singleton getInstance(){
        return instance;
    }
}
